This is my demonstration of what I learnt during week 2 on the different ways and packages that we can visuailze data in python.
Daniel Beckley - 8846774
For the purpose of this demonstration, I will be using the same data for each of the graphs below, just to properly understand how the syntax for each of them work.
As I believe this will make me understand how each graph works and their peculiarities because this will guide my decision to know which graphs to use on future projects.
The graphs will also just be a line graph.
The graphs will be illustrating how much time I spent programming in the last week.
x_data = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']
y_data = [2, 8, 7.5, 5, 7.9, 6, 3]
You can learn more here - Matplotlib Documentation
# Import the necessary libraries
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots() # Create a figure containing a single axes.
fig.suptitle('My first visualization in matplotlib')
# this is where we pass the data we want to plot
ax.plot(x_data, y_data, marker='o') # Plot some data on the axes.
#we want the y axis to go from 0 to 12
ax.set_ylim(0, 12)
# setting the label for the x and y axis.
ax.set_xlabel('days of the week')
ax.set_ylabel('number of hours programming')
Text(0, 0.5, 'number of hours programming')
Learn more about plotly in its documentation
Importing the necessary libraries for plotly
import plotly.express as px
import plotly as plotly
the line below is specifically to make sure our plotly graph is still interactive after converting to html
plotly.offline.init_notebook_mode()
In plotly, this is how we can create the data for our graph
graph_data = {"days_of_week":x_data, "hour_per_day":y_data}
This is how we pass the data to plot in plotly, we also tell it what the x axis and y axis should be based on "columns" in our data
figure = px.line(graph_data, x="days_of_week", y="hour_per_day")
figure.show()
Because I like Plotly's interactivity, here is a scatter diagram using the same data.
scatterg = px.scatter(graph_data, x="days_of_week", y="hour_per_day", size="hour_per_day")
scatterg.show()
# we install the library we need for seaborn
import seaborn as sns
sns.set_theme(style="darkgrid")
# seaborn works very similar to plotly in terms of telling it what data we want to plot
data_plot = {"days_of_week":x_data, "hour_per_day":y_data}
sns.lineplot(data=data_plot, x="days_of_week", y="hour_per_day")
<Axes: xlabel='days_of_week', ylabel='hour_per_day'>
| Lab | Title |
|---|---|
| Lab 1 | Git and Github |
| Lab 2 | Data Visualization and Publication |
| Lab 3 | Univariate Linear Regression |
| Lab 4 | Multivariate Linear and Polynomial Regression |
| Lab 5 | Cross Validation |
| Lab 6 | Logistic Regression |
| Lab 7 | Performance Metrics for Classification |
| Lab 8 | Dot Product and Matrix Multiplication in PyTorch and Tensorflow |